/*
 * Copyright 2012 NJUT  qixiaobo. All rights reserved.
 */
package com.fujitsu.nanjing.tieba.model;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import com.fujitsu.nanjing.tieba.dao.CoreTopicDAOImpl;
import com.fujitsu.nanjing.tieba.ibator.CoreTopic;
import com.ibatis.sqlmap.client.SqlMapClient;

/**
 * Topic.java
 * 
 * @author Qixiaobo-win8
 */
@Repository
public class Topic extends CoreTopicDAOImpl {
	@Resource
	private SqlMapClient sqlMapClient;
	@PostConstruct
	public void initSqlMapClient() {
		super.setSqlMapClient(sqlMapClient);
	}
	public CoreTopic getLastTopicByBoardId(int boardId) {
		CoreTopic coreTopic = (CoreTopic) getSqlMapClientTemplate()
				.queryForObject("core_topic.selectLastTopicByBoardId", boardId);
		return coreTopic;
	}
	public int countTopicByBoardId(int boardId) {
		return (Integer) getSqlMapClientTemplate().queryForObject(
				"core_topic.countTopicByBoardId", boardId);
	}
	public int countTopics() {
		return (Integer) getSqlMapClientTemplate().queryForObject(
				"core_topic.countTopics");
	}
	public int countDigests() {
		return (Integer) getSqlMapClientTemplate().queryForObject(
				"core_topic.countDigests");
	}
	public int sumOfVisits() {
		return (Integer) getSqlMapClientTemplate().queryForObject(
				"core_topic.sumOfVisits");
	}
	public int countMonthNewTopics() {
		return (Integer) getSqlMapClientTemplate().queryForObject(
				"core_topic.countMonthNewTopics");
	}

	@SuppressWarnings("unchecked")
	public List<CoreTopic> highColorOrTopScope(int begin) {
		return getSqlMapClientTemplate().queryForList(
				"core_topic.highColorOrTopScope", begin);

	}
	@SuppressWarnings("unchecked")
	public List<CoreTopic> searchTopic(HashMap<String, Object> map) {
		return getSqlMapClientTemplate().queryForList("core_topic.searchTopic",
				map);

	}
	@SuppressWarnings("unchecked")
	public List<CoreTopic> searchTopicAndReplies(HashMap<String, Object> map) {
		return getSqlMapClientTemplate().queryForList(
				"core_topic.searchTopicAndReplies", map);

	}
	public int searchTopicCount(HashMap<String, Object> map) {
		return (Integer) getSqlMapClientTemplate().queryForObject(
				"core_topic.searchTopicCount", map);
	}
	public int searchTopicAndRepliesCount(HashMap<String, Object> map) {
		return (Integer) getSqlMapClientTemplate().queryForObject(
				"core_topic.searchTopicAndRepliesCount", map);
	}
	public int countTopicsPages(int boardid) {
		return (Integer) getSqlMapClientTemplate().queryForObject(
				"core_topic.selectTopicsPages", boardid);
	}
	@SuppressWarnings("unchecked")
	public List<CoreTopic> selectTopicsByBoardIdAndPageBegin(
			Map<String, Object> map) {
		return getSqlMapClientTemplate().queryForList(
				"core_topic.selectTopicsByBoardIdAndPageBegin", map);
	}
	public static final class TopicCondictionMap {
		private TopicCondictionMap() {

		}
		private final static TopicCondictionMap map = new TopicCondictionMap();
		public static TopicCondictionMap getInstance() {
			return map;
		}
		private String keyword;
		public String getKeyword() {
			return keyword;
		}
		public void setKeyword(String keyword) {
			this.keyword = keyword;
		}
		public String getUserid() {
			return userid;
		}
		public void setUserid(String userid) {
			this.userid = userid;
		}
		public int getOffset() {
			return offset;
		}
		public void setOffset(int offset) {
			this.offset = offset;
		}
		public String getBoardid() {
			return boardid;
		}
		public void setBoardid(String boardid) {
			this.boardid = boardid;
		}

		public String getSearchfield() {
			return searchfield;
		}
		public void setSearchfield(String searchfield) {
			this.searchfield = searchfield;
		}
		private String userid;
		private int offset;
		private String boardid;
		private String searchfield;
	}
}
